package widget;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class RecycleUtil {
    private Activity staticcontext;
    private RecyclerView recyclerView;

    public RecycleUtil(Activity staticcontext) {
        this.staticcontext = staticcontext;
    }

    public static RecycleUtil build(Context context) {
        return new RecycleUtil((Activity) context);
    }

    public RecycleUtil recv(int id) {
        recyclerView = (RecyclerView) ((Activity) staticcontext).findViewById(id);
        return this;
    }

    public RecycleUtil recv(View id) {
        recyclerView = (RecyclerView) id;
        return this;
    }

    public RecycleUtil grid(Context context, int columns) {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(staticcontext, columns);
        recyclerView.setLayoutManager(gridLayoutManager);
        return this;
    }
    public RecycleUtil gridLines(Context context, int columns) {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(staticcontext, columns);
        gridLayoutManager.setOrientation( LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(gridLayoutManager);
        return this;
    }
    public RecycleUtil linear(boolean horizontal) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(staticcontext);
        linearLayoutManager.setOrientation(horizontal ? LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        return this;
    }

    public RecyclerView get() {
        return recyclerView;
    }
}
